package server.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import message.GroupMembersRequestMessage;
import message.GroupMembersResponseMessage;
import server.session.GroupSession;
import server.session.GroupSessionFactory;
@ChannelHandler.Sharable
public class GroupMembersRequestMessageHandler extends SimpleChannelInboundHandler<GroupMembersRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, GroupMembersRequestMessage groupMembersRequestMessage) throws Exception {
        String groupName = groupMembersRequestMessage.getGroupName();
        GroupSession groupSession = GroupSessionFactory.getGroupSession();
        channelHandlerContext.writeAndFlush(new GroupMembersResponseMessage(groupSession.getMembers(groupName)));
    }
}
